<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <style>
        li{
            /* list-style: none;*/
        }
        #content{
            white-space: pre-line;
        }
        pre{
            white-space:pre-line;
        }
    </style>
    <script src="js/jquery-3.4.1.min.js"></script>
</head>
<body>
<h1>试题信息</h1>
<div>
    <div>
        <pre id="content"><c:out value="${q.title}"/></pre>
        <c:if test="${q.picture!=null}">
            <img src="${q.pictBase64}"/>
        </c:if>
    </div>
    <p>
    <ol type="A">
        <c:forEach items="${q.options}" var="op" varStatus="s">
            <li>
            <pre>
                 <input type="checkbox" name="youanswer" value="${s.index}"/>:<c:out value="${op}"/>
            </pre>
            </li>
        </c:forEach>
    </ol>

    </p>
    <p >
        <span style="display: none" id="answer"><%--${q.answers}--%></span>
    </p>
    <p>
    <pre style="display: none" id="questionanalysis">
    <%--${q.questionanalysis==null?'此题太简单，没有解析':q.questionanalysis}--%>
    </pre>
    </p>
    <%--<p>知识点：${q.sect.parent.sectionname}-> ${q.sect.sectionname}</p>--%>
    <%--<p>
        创建时间:<fmt:formatDate value="${q.createdate}" pattern="yyyy-MM-dd HH:mm:ss"/>
    </p>--%>
    <p id="result"></p>
    <p>
        <a href="#"> <button type="button" id="next">下一题</button></a>
        <button type="button" id="confirm">看对错</button>
        <button type="button" id="seeanser">看答案</button>
        <button type="button" id="seeanalyze">看试题分析</button>
    </p>
</div>
<script>
    $(function () {


        $("#next").click(function () {
            //alert(window.location.search);
            //window.location="selectQues.stu"+window.location.search+"&testids="+setTestQuestion().join(",");
            window.location="selectQues.stu"+window.location.search+"&v="+${q.id};
        });
        $("#confirm").click(function () {
            let ar=$(":checkbox[name=youanswer]:checked");
            let str="";
            for(let i=0;i<ar.length;i++){
                str+=ar[i].value;
                if(i<ar.length-1){
                    str+=","
                }
            }
            //alert(str);
            //发一个请求记录这个题目，结果是否正确，。。。
            $("#result").html(str==$("#answer").text()?"正确":"错误");
            //发送一个ajax,记录一下此题
            $.post("savePractise.stu",{qid:${q.id},result:str==$("#answer").text()},function (r) {
                alert(JSON.stringify(r));
            });
        });
        //看答案：
        $("#seeanser").click(function () {
            console.log("${q.id}");
            $.get("showAnser.stu",{qid:${q.id}},function (r) {
                console.log(r);
                if(r.success){
                    //答案放到r.data中
                    $("#answer").html(r.data.answerStr).show(600);
                    return;
                }
                alert("出错了，原因是："+r.msg);
            }).fail(function (r) {
                alert("出错了，可能你没有登录，"+r.responseText);
            });
        });
        //看试题分析
        $("#seeanalyze").click(function () {
            //
            $.post("kofen.stu",function (kf) {
                if (kf.success){
                    $("#questionanalysis").show(1000);
                } else {
                    alert("积分不够，请充值！");
                    window.location.href="recharge.jsp";
                }
            });
        });
    });
</script>
</body>
</html>
